package com.itheima.pinda;


import com.itheima.pinda.validator.config.EnableFormValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author llhuang10
 * @date 2021/9/4 19:24
 */
@Slf4j
@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrix      // 开启熔断
@EnableFeignClients(value = {
        "com.itheima.pinda",
})
@EnableTransactionManagement
@EnableFormValidator
public class GoodsServerApplication {
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext context = SpringApplication.run(GoodsServerApplication.class, args);

        // 启动完成后, 在控制台提示项目启动成功, 并且输出当前服务对应的swagger接口文档地址
        // environment 可以获取配置文件中的信息
        ConfigurableEnvironment env = context.getEnvironment();
        String appName = env.getProperty("spring.application.name");
        // 会获得局域网的ip, 会不准确
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        // 会从配置中心 nacos中获得
        String port = env.getProperty("server.port");

        String protocol = "http";
        log.info(
                "\n----------------------------------------------------------\n\t"
                        + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t"
                        + "External: \t{}://{}:{}\n\t"
                        + "Swagger: \t{}://localhost:{}/doc.html\n\t"
                        + "Profile(s): \t{}\n----------------------------------------------------------",
                appName, protocol, port, protocol, hostAddress, port, protocol, port, env.getActiveProfiles());
    }
}
